package cn.autumnorange.app;

import cn.autumnorange.app.common.rpc.lock.RPCIdempotentLockTarget;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.security.crypto.codec.Base64;
import org.springframework.session.data.redis.config.annotation.web.http.EnableRedisHttpSession;
// 集成redisSession下,测试得出授权服务器需要header传入SESSIONID,SESSION俩个值;
// DefaultSaveRequest()才能获取到本次会话客户端服务器的请求信息 对于客户端的JSESSIONID应该还要传入
/**
 * Created on 2018/4/28.
 *
 * @author zlf
 * @since 1.0
 */
// 解决 CROSSSLOT Keys in request don't hash to the same slot
// https://blog.csdn.net/zl_momomo/article/details/81911705
@SpringBootApplication
@EnableHystrix
@EnableEurekaClient
// @EnableDiscoveryClient
// @EnableDiscoveryClient与@EnableEurekaClient区别https://www.jianshu.com/p/f6db3117864f
@EnableFeignClients
@EnableRedisHttpSession(
    maxInactiveIntervalInSeconds = 7200,
    //      maxInactiveIntervalInSeconds = 86400*30
    redisNamespace = "spring:session{springSessionHashTag}") // RedisHttpSession过期时间(秒)
@Slf4j
public class AuthorizationServerApplication {

    public static void main(String[] args) {
    String encode = new String(Base64.encode("merryyou:merryyou".getBytes()));
    log.info("encode:merryyou \n {}", encode);

    encode = new String(Base64.encode("zuul:zuul".getBytes()));
    log.info("encode:zuul\n {}", encode);

    encode = new String(Base64.encode("client-a:client-a".getBytes()));
    log.info("encode:client-a\n {}", encode);
    SpringApplication.run(AuthorizationServerApplication.class, args);
  }
  //
  //  @GetMapping("/userJwt")
  //  public Object getCurrentUserJwt(Authentication authentication, HttpServletRequest request)
  //      throws UnsupportedEncodingException {
  //    log.info(
  //        "【SecurityOauth2Application】 getCurrentUserJwt authentication={}",
  //        JsonUtil.toJson(authentication));
  //
  //    String header = request.getHeader("Authorization");
  //    String token = StringUtils.substringAfter(header, "bearer ");
  //
  //    Claims claims =
  //        Jwts.parser()
  //            .setSigningKey(oAuth2Properties.getJwtSigningKey().getBytes("UTF-8"))
  //            .parseClaimsJws(token)
  //            .getBody();
  //    String blog = (String) claims.get("blog");
  //    log.info("【SecurityOauth2Application】 getCurrentUser1 blog={}", blog);
  //
  //    return authentication;
  //  }
  //
  //  @GetMapping("/userRedis")
  //  public Object getCurrentUserRedis(Authentication authentication) {
  //    log.info(
  //        "【SecurityOauth2Application】 getCurrentUserRedis authentication={}",
  //        JsonUtil.toJson(authentication));
  //  //
  //    return authentication;
  //  }

}
